<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
         * 
         * 目标:认识Promise状态
         * 
         */
        // 1。创建Promise对象 (pending-待定状态)
        const p = new Promise((resolve, reject) => {
            // Promise对象创建时，这里的代码都会执行了
            console.log('Promise对象内开始执行')
                // 2.执行异步代码
            setTimeout(() => {
                // resolve() =>'fulfilled状态-已兑现'=> then()
                // resolve(模拟AJAX请求-成功结果)
                // reject() =>'rejected状态-已拒绝'=> catch()
                reject(new Error('模拟AJAX请求-失败结果'))
            }, 2000)
        })
        console.log(p);
        // 3.获取结果
        p.then(result => {
            console.log(result);
        }).catch(error => {
            console.log(error);
        })
    </script>
</body>

</html>